Contract-Java: Design by Contract in Java with Safe Error Handling

نویسندگان

  • Miguel Oliveira e Silva
  • Pedro G. Francisco
چکیده

Design by Contract (DbC) is a programming methodology in which the meaning of program entities, such as methods and classes, is made explicit by the use of programming predicates named assertions. A false assertion is always a manifestation of an incorrect program. This simple founding idea, when properly applied, give programmers a tool able to specify, test, debug, document programs, as well as a mechanism to construct a simple, safe and sane error handling mechanism. Nevertheless, although well adapted to object-oriented programming (and other popular techniques such as unit testing), DbC still has a very low practical acceptance and application. We believe that one of the main reasons for such is the lack of a proper support for it in many programming languages currently in use (such as Java). A complete support for DbC requires not only the ability to specify assertions; but also the necessity to distinguish different kinds of assertions, depending of what is being asserted; a proper integration in object-oriented programming; and, finally, a coherent connection with error handling mechanisms. It is in this last requirement that existing tools that extend Java with DbC mechanisms completely fail to properly, and coherently, integrate DbC within Java programming. The dominant practices for systematically handling failures in programming languages are not DbC based, using instead a defensive programming approach, either by using normal languages mechanisms (as in programming language C) or by the use of typed exceptions in try/catch based exception mechanisms. In this article, we will present and justify the requirements posed on programming languages for a complete support for DbC; On the context of the last presented requirement – error handling – defensive programming will be discussed and criticized; It will be showed that, unlike Eiffel’s original DbC error handling, existing typed exceptions in try/catch based exception mechanisms are not well adapted to algorithmic abstraction provided by methods; Finally, a new DbC Java extension named Contract-Java will be presented and it will be showed that it is coherently integrated both with Java existing mechanisms and DbC. It will be presented an innovative Contract-Java extension to DbC that automatically generates debugging information for (nonrescued) contract failures, that we believe further enhances the DbC debugging capabilities. 1998 ACM Subject Classification D.2.4 Software/Program Verification, D.2.5 Testing and Debugging, D.3.4 Processors

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

jContractor: A Reflective Java Library to Support Design by Contract

jContractor is a purely library based approach to support Design By Contract specifications such as preconditions, postconditions, class invariants, and recovery and exception handling in Java. jContractor uses an intuitive naming convention, and standard Java syntax to instrument Java classes and enforce Design By Contract constructs. The designer of a class specifies a contract by providing c...

متن کامل

Supporting Design by Contract in Java

Design by Contract is a valuable design method for trusted software components. Eiffel shows how to provide appropriate language support for it. However, no such concepts currently exist in Java. Full integration of them into Java may help to improve and guarantee the quality of Java classes. We briefly compare several approaches to extend Java in this way and present our model and a compiler t...

متن کامل

Static and Dynamic Contract Verifiers For Java

Design By Contract (DBC) is a systematic approach to specifying and implementing object-oriented software systems. DBC has been proved to greatly benefit software development. However, Java does not natively support DBC. We have developed a comprehensive solution to bring DBC into Java. The static and dynamic contract verifier is the most crucial part of the solution. We have developed a toolse...

متن کامل

Contracts for Java: A Practical Framework for Contract Programming

This report introduces Contracts for Java (Cofoja), a new framework for contract programming in Java, and the successor to Johannes Rieken’s Modern Jass. Based on the same standard Java technologies such as annotation processing and bytecode instrumentation, it improves upon the stub-based separate compilation strategy of its predecessor. Contracts for Java promotes a minimalistic yet expressiv...

متن کامل

Contract4J for Design by Contract in Java: Design Pattern-Like Protocols and Aspect Interfaces

Recent trends in Aspect-oriented Design (AOD) have emphasized interface-based modularity constructs that support noninvasive advising of components by aspects in a robust and flexible way. We show how the AspectJ-based tool Contract4J supports Design by Contract in Java using two different forms of a design patternlike protocol, one based on Java 5 annotations and the other based on a JavaBeans...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2014